//
//  WATFSpeedResultViewController.swift
//  WiFiFaster
//
//  Created by one on 2023/12/28.
//

import UIKit

class WATFSpeedResultViewController: WATFResultViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        
    }
    
    // MARK: - watf action
    override func watf_layout() -> UICollectionViewFlowLayout {
        let watf_layout = UICollectionViewFlowLayout()
        watf_layout.itemSize = CGSize(width: 146, height: 84)
        watf_layout.minimumLineSpacing = 12
        watf_layout.minimumInteritemSpacing = 12
        return watf_layout
    }
    override func watf_collectionViews() {
        super.watf_collectionViews()
        watf_contentView.addSubview(watf_tryButton)
        watf_collectionView.snp.makeConstraints { make in
            make.size.equalTo(CGSize(width: watf_SCREEN_WIDTH-40, height: 232))
            make.centerX.equalToSuperview()
            make.top.equalTo(watf_navView.snp.bottom).offset(40)
        }
        watf_tryButton.snp.makeConstraints { make in
            make.size.equalTo(CGSize(width: 274, height: 58))
            make.centerX.equalToSuperview()
            make.top.equalTo(watf_collectionView.snp.bottom).offset(-10)
            make.bottom.equalToSuperview().offset(-15)
        }
        watf_collectionView.backgroundColor = WATFCommon.watf_getHXColorValue(rgb: 0x322E2B)
        watf_collectionView.layer.cornerRadius = 16
        watf_collectionView.register(WATFSpeedResultCell.classForCoder(), forCellWithReuseIdentifier: WATFSpeedResultCell.watf_viewToString)
        watf_collectionView.contentInset = UIEdgeInsets(top: 22, left: 12, bottom: 0, right: 12)
        watf_collectionView.dataSource = self
        watf_collectionView.delegate = self
    }
    @objc func watf_tryClick() {
//        watf_funcClickModel(watf_funcModel: WATFFuncModel(watf_type: .watf_speed))
        self.navigationController?.popToRootViewController(animated: true)
        if  WATFManager.watf_manager.watf_smartFTVModel != nil {
            WATFManager.watf_manager.watf_smartFTVModel?.watf_select = true
            let _ = WATFManager.watf_manager.watf_ftvModels.map { watf_model in
                return watf_model.watf_select = false
            }
        }
        
        
        NotificationCenter.default.post(name: watf_ftvConnect_noti, object: nil)
    }
    // MARK: - watf lazy
    lazy var watf_tryButton: UIButton = {
        let watf_tryButton = UIButton()
        watf_tryButton.setBackgroundImage(UIImage(named: "watf_result_speedTry"), for: .normal)
        watf_tryButton.addTarget(self, action: #selector(watf_tryClick), for: .touchUpInside)
        return watf_tryButton
    }()
}
extension WATFSpeedResultViewController: UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 4
    }
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let watf_cell = collectionView.dequeueReusableCell(withReuseIdentifier: WATFSpeedResultCell.watf_viewToString, for: indexPath) as! WATFSpeedResultCell
        guard let watf_resultModel = watf_resultModel as? WATFSpeedModel else { return watf_cell }
        if indexPath.row == 0 {
            watf_cell.watf_titleLabel.text = "Download"
            watf_cell.watf_valueLabel.text = watf_resultModel.watf_download
        }
        if indexPath.row == 1 {
            watf_cell.watf_titleLabel.text = "Upload"
            watf_cell.watf_valueLabel.text = watf_resultModel.watf_upload
        }
        if indexPath.row == 2 {
            watf_cell.watf_titleLabel.text = "Jitter"
            watf_cell.watf_valueLabel.text = watf_resultModel.watf_jitter
        }
        if indexPath.row == 3 {
            watf_cell.watf_titleLabel.text = "Loss"
            watf_cell.watf_valueLabel.text = watf_resultModel.watf_loss
        }
        return watf_cell
    }
}
